# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
pkgname=py3-amqp
pkgver=5.2.0
pkgrel=2
pkgdesc="an AMQP implementation"
url="https://pypi.org/project/amqp/"
# s390x: tests fail with OSError: [Errno 99] Address not available
arch="noarch !s390x"
license="BSD-3-Clause"
depends="py3-vine python3"
makedepends="py3-setuptools py3-gpep517 py3-wheel"
checkdepends="py3-pytest py3-vine py3-case py3-nose py3-mock py3-pytest-rerunfailures rabbitmq-server"
subpackages="$pkgname-pyc"
source="
	$pkgname-$pkgver-gh.tar.gz::https://github.com/celery/py-amqp/archive/refs/tags/v$pkgver.tar.gz
	tests-server_certificate.pem
	tests-server_key.pem
	tests-ca_certificate.pem
	tests_undockerify.patch
"
builddir="$srcdir"/py-amqp-$pkgver

replaces="py-amqp" # Backwards compatibility
provides="py-amqp=$pkgver-r$pkgrel" # Backwards compatibility

build() {
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	# generate test config file to use test certs that are taken from
	# Dockerfile in tarred source code
	mkdir -p "$srcdir"/rabbitmq-tests
	echo "loopback_users = none
listeners.ssl.default = 5671
ssl_options.cacertfile = $srcdir/tests-ca_certificate.pem
ssl_options.certfile   = $srcdir/tests-server_certificate.pem
ssl_options.keyfile    = $srcdir/tests-server_key.pem
ssl_options.verify     = verify_peer
ssl_options.fail_if_no_peer_cert = true
" > "$srcdir"/rabbitmq-tests/server.conf
	RABBITMQ_CONFIG_FILE="$srcdir"/rabbitmq-tests/server.conf \
		RABBITMQ_SERVER_ERL_ARGS="-setcookie rabbit" \
		RABBITMQ_LOG_BASE="$srcdir"/rabbitmq-tests/log \
		RABBITMQ_PID_FILE="$srcdir"/rabbitmq-tests/rabbit.pid \
		RABBITMQ_MNESIA_BASE="$srcdir"/rabbitmq-tests/mnesia \
		rabbitmq-server &
	sleep 5 # Wait for rabbitmq to start
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	.testenv/bin/python3 -m pytest -v || local FAIL=true
	pkill rabbitmq-server
	if [ "$FAIL" = "true" ]; then
		return 1
	fi
}

package() {
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

sha512sums="
7d210c55c0873a5c346ce52d0e9ee258726fac1d359a98c7fe83a460712765979f1c62ab172a9447bbebb190f4b43f1a26ef9c074b61b348c85c4a29539f0873  py3-amqp-5.2.0-gh.tar.gz
523e2ed6ac16f17b29b96cd2c808132e4292755114bc5ee52a920c37dfba3f6e78e8076dcded85188eb7ff2e4825f38f73bd51c7a18da458317bbac4f7c0c08f  tests-server_certificate.pem
5510848425a2ddd965c5e7cb0a14e185f73ed6f5b006eed0cf4cc47d593083d464c4b03e5ac9ee3692c85c622a6b82f8f1158cff52e25d9fb604f5faf5fc3be9  tests-server_key.pem
74dedc4c373e14008b4a808ce29a8883e5243c5f4d97b282e46f335a8cab02e89e9e34c6d080a8ccd3b1ae9f9b51059430dc1e5875e06c968096d19d1f2f66c8  tests-ca_certificate.pem
0d547c79fd5a71b687ac12ad32e6adf7064f811ad1ac57978cde47c36f44de15b3f8c1789c24fcccc9823670d376158479c85a65f92a8fd5fa8413357d10fb6d  tests_undockerify.patch
"
